package cn.wolfcode.ssm.service.impl;

import cn.wolfcode.ssm.domain.SystemDictionary;
import cn.wolfcode.ssm.mapper.SystemDictionaryMapper;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.service.ISystemDictionaryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryServiceImpl implements ISystemDictionaryService {

    @Autowired
    private SystemDictionaryMapper systemDictionaryMapper;

    @Override
    public void deleteById(Long id) {
        if(id != null){
            systemDictionaryMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public void save(SystemDictionary systemDictionary) {
        systemDictionaryMapper.insert(systemDictionary);

    }

    @Override
    public SystemDictionary selectById(Long id) {
        if(id != null){
            return systemDictionaryMapper.selectByPrimaryKey(id);
        }
        return null;
    }

    @Override
    public PageInfo<SystemDictionary> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<SystemDictionary> systemDictionarys = systemDictionaryMapper.selectAll();
        return new PageInfo<>(systemDictionarys);
    }

    @Override
    public List<SystemDictionary> ListAll() {
        return systemDictionaryMapper.selectAll();
    }


    @Override
    public void updateById(SystemDictionary systemDictionary) {
        systemDictionaryMapper.updateByPrimaryKey(systemDictionary);
    }
}
